<!--
 * @Description: 描述信息
 * @Version: 版本号
 * @Author: xuebao
 * @Date: 2023-12-04 15:14:43
 * @LastEditors: renmengxue
 * @LastEditTime: 2023-12-08 15:08:56
-->
<template>
  <div class="container">
    <GlobalHeader :data="currentUser" :isLogin="isLogin" />

    <Loader v-if="isLoading" text="拼命加载中" background="rgba(0,0,0,0.8)" />
    <router-view></router-view>
    <!-- <Message type="error" :message="error.message" v-if="error.status" /> -->
    <footer class="text-center py-4 text-secondary bg-light mt-6">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">© 2020 者也专栏</li>
          <li class="list-inline-item">课程</li>
          <li class="list-inline-item">文档</li>
          <li class="list-inline-item">联系</li>
          <li class="list-inline-item">更多</li>
        </ul>
      </small>
    </footer>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, onMounted, watch } from 'vue'
import { useUserStore } from './store/user'
import 'bootstrap/dist/css/bootstrap.min.css'
import GlobalHeader from './components/GlobalHeader.vue'
import { useStore } from 'vuex'
import Loader from './components/Loader.vue'
import { GlobalDataProps } from './store'
// import Message from './components/Message.vue'
import CreateMessage from './components/CreateMessage'
import { useGlobalStore } from './store/global'
import axios from 'axios'
export default defineComponent({
  name: 'App',
  components: {
    GlobalHeader,
    Loader
    // Message

  },
  setup() {
    const userStore = useUserStore()
    const globalStore = useGlobalStore()
    const store = useStore<GlobalDataProps>()
    const currentUser = computed(() => userStore.data)
    const isLogin = computed(() => userStore.isLogin)
    const isLoading = computed(() => globalStore.loading)
    const error = computed(() => globalStore.error)
    /***
     * 使用watch侦听error里面的变化
     */

    watch(() => error.value.status, () => {
      const { status, message } = error.value
      if (status && message) {
        const messageWay = CreateMessage(message, 'error')
        setTimeout(() => {
          messageWay.destroy()
        }, 2000)
      }
    })

    return {
      currentUser,
      isLoading,
      error,
      isLogin
    }
  }
})
</script>

<style></style>
